package com.hai.qtalk.bean;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.hai.qtalk.bean.Friendship;
import com.hai.qtalk.bean.User;

/**
 * 好友分组的实体类
 * @author xinhai
 */
@Entity
@Table(name = "group", catalog = "mydb")
public class Group implements java.io.Serializable {

	// Fields

	private Integer GId;
	private User user;
	private String GName;
	private Set<Friendship> friendships = new HashSet<Friendship>(0);

	// Constructors

	/** default constructor */
	public Group() {
	}

	public Group(User user, String GName){
		this.user = user;
		this.GName = GName;
	}
	
	/** full constructor */
	public Group(User user, String GName, Set<Friendship> friendships) {
		this.user = user;
		this.GName = GName;
		this.friendships = friendships;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "g_id", unique = true, nullable = false)
	public Integer getGId() {
		return this.GId;
	}

	public void setGId(Integer GId) {
		this.GId = GId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "u_id")
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "g_name", length = 45)
	public String getGName() {
		return this.GName;
	}

	public void setGName(String GName) {
		this.GName = GName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "group")
	public Set<Friendship> getFriendships() {
		return this.friendships;
	}

	public void setFriendships(Set<Friendship> friendships) {
		this.friendships = friendships;
	}

}